const Mock = require('mockjs')

const token = "zheshiyigetokenlingpaiziduan"
module.exports = function (app) {  //导出的这个函数是用于webpack配置的devServer下的before属性(可以理解为拦截器)
    if (process.env.VUE_APP_MOCK === 'true') {   //vue-cli的webpack环境变量,用于后端接口好了不使用拦截
        //登录
        app.post('/api/login', (req, res) => {
            res.json(Mock.mock({
                code: 200,
                info: '登录成功',
                data: {
                    token: token
                }
            }))
        })

        //获取登录用户信息
        app.get('/api/getUserInfo', (req, res) => {   //mock配置字段相关规则很简单,去看看mock官方文档就会了  http://mockjs.com/
            res.json(Mock.mock({
                code: 200,
                info: '',
                data: {
                    userInfo: {
                        name: '@cname()',
                        id: '@id()',
                        'age|18-40': 0,
                        email: '@email()',
                        image: "@image('100x100', '#50B347', '#FFF', 'mock')",
                        description: "@paragraph()",
                        'roleId': 1,
                    },
                    menuList: [
                        {
                            text: "主页",
                            icon: "el-icon-s-home",
                            path: "/home",
                            name:"home"

                        },
                        {
                            text: "角色",
                            icon: "el-icon-s-custom",
                            children: [
                                {
                                    text: "角色子菜单1",
                                    icon: "el-icon-help",
                                    path: "/role/subRole1",
                                    name:'role1'
                                },
                                {
                                    text: "角色子菜单2",
                                    icon: "el-icon-help",
                                    path: "/role/subRole2",
                                    name:'role2'

                                }
                            ]
                        },
                        {
                            text: "高德地图",
                            icon: "el-icon-map-location",
                            path: "/gaodeMap",
                            name:"gaodeMap"
                        },
                    ]

                }
            }))
        })



    }
}



